//
//  DestinationResultCollectionViewCell.m
//  TripGo
//
//  Created by dllo on 15/7/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DestinationResultCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@implementation DestinationResultCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        
        self.img = [[UIImageView alloc] init];
        [self.contentView addSubview:self.img];
        [_img release];
        
        self.image = [[UIImageView alloc] init];
        [self.contentView addSubview:self.image];
        [_image release];
        
        self.labelT = [[UILabel alloc] init];
        self.labelT.textColor = [UIColor whiteColor];
        self.labelT.textAlignment = NSTextAlignmentCenter;
        [self.image addSubview:self.labelT];
        [_labelT release];
        
        self.labelN = [[UILabel alloc] init];
        self.labelN.textAlignment = NSTextAlignmentCenter;
        self.labelN.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.labelN];
        [_labelN release];
    }
    return self;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.img.frame = CGRectMake(0, 0, layoutAttributes.size.width, layoutAttributes.size.height - 30);
    self.image.frame = CGRectMake(0, self.img.frame.size.height - 30, layoutAttributes.size.width, 30);
    self.labelT.frame = CGRectMake(0, 0, layoutAttributes.size.width, 30);
    self.labelN.frame = CGRectMake(0, self.img.frame.origin.y + self.img.frame.size.height, layoutAttributes.size.width, 30);
}
- (void)setDes:(Destination *)des
{
    if (_des != des) {
        [_des release];
        _des = [des retain];
    }
    [self.img setImageWithURL:[NSURL URLWithString:des.image_url] placeholderImage:[UIImage imageNamed:@"place_holder.jpg"]];
    self.labelT.text = [NSString stringWithFormat:@"%ld篇游记", (long)des.attraction_trips_count.integerValue];
    self.labelN.text = des.name;
}
@end
